
const domainName = getApp().globalData.domainName
const dataType = 'json'
const header = {'content-type':'application/x-www-form-urlencoded'}
const method = 'POST'
const responseType = 'text'




const add_submit=(that)=>{
  wx.showModal({
    content: '确定提交吗？',
    showCancel: true,
    title: '提示',
    success: res => {
      if(res.confirm){
        wx.request({
          url: domainName + '/mana_caac_uavLevel_submit',
          data: {
            input_name:that.data.name,
          },
          dataType: dataType,
          enableCache: true,
          enableHttp2: true,
          enableQuic: true,
          header: header,
          method: method,
          responseType: responseType,
          timeout: 0,
          success: res => {
            wx.showToast({
              title: '创建完成',
              duration: 2000,
              icon: 'success',
              mask: false,
            })
            that.setData({
              show_mask:false,
              name:'',
              list:res.data.uavLevel_list
            })
          },
        })
      }
    },
  })
}


 // 加载权限列表
const page_init=(that)=>{
  wx.request({
    url: domainName + '/load_caac_uavLevel_list',
    data: {},
    dataType: dataType,
    enableCache: true,
    enableHttp2: true,
    enableQuic: true,
    header: header,
    method: method,
    responseType: responseType,
    timeout: 0,
    success: res => {
      that.setData({
        list:res.data.uavLevel_list,
      })
    },
  })
}

// 设置选项
const set_opt=(that,e)=>{
  let index = e.currentTarget.id
  var row_id = that.data.list[index].id
  var name = that.data.list[index].name
  wx.showActionSheet({
    itemList: ['修改'],
    success: res => {
      console.log('tapIndex',res.tapIndex)
      if(res.tapIndex==0){
        wx.showModal({
          content:name,
          editable: true,
          placeholderText: '请输入新名词',
          showCancel: true,
          title: '修改名称',
          success: res => {
            if(res.confirm){
              wx.request({
                url: domainName + '/update_uavLevel_list_name',
                data: {
                  row_id:row_id,
                  new_name:res.content,
                },
                dataType: dataType,
                enableCache: true,
                enableHttp2: true,
                enableQuic: true,
                header: header,
                method: method,
                responseType: responseType,
                timeout: 0,
                success: res => {
                  wx.showToast({
                    title: '修改完成',
                    duration: 1500,
                    icon: 'success',
                  })
                  that.setData({
                    show_mask:false,
                    name:'',
                    list:res.data.uavLevel_list,
                  })
                },
              })
            }
          },
        })
      }
    },
  })
}


module.exports={
  set_opt:set_opt,
  add_submit:add_submit,
  page_init:page_init,
}